#include"comm.hpp"
#include"log.hpp"
int main()
{
    Log log;
    //log.Enable(PrintfMethod::ClassFile);
    //创建信道
    int ret=mkfifo(FIFO_FILE,MODE);
    if(ret<0)
    {
        log.logmessage(Error,"%s文件已存在退出码: %d",FIFO_FILE,FILE_EXIIED);
        exit(FILE_EXIIED);
    }
    int fd=open(FIFO_FILE,O_RDONLY);
    std::cout<<"open mkfifo文件成功"<<std::endl;
    log.logmessage(Info,"open mkfifo文件成功");
    char buffer[SIZE];
    while(true)
    {
        int size=read(fd,buffer,sizeof(buffer));
       if(size==0)
       {
        int ret=unlink(FIFO_FILE);
        if(ret<0)
        {
            log.logmessage(Error,"mkfifo文件删除失败退出码: %d",DELET_FILE_ERROR);
            exit(DELET_FILE_ERROR);
        }
        log.logmessage(Debug,"server quit");
        break;
       }
       else if(size<0)
       {
            log.logmessage(Error,"read失败退出码: %d",READ_ERROR);
            exit(READ_ERROR);
       }
        //buffer[size]=0;
        std::cout<<"Client Say@ "<<buffer<<std::endl;
        log.logmessage(Info,"Client Say@ %s",buffer);
    }


   

}
